<template>
    <h2>添加页面</h2>

    <table border="1">
        <tr>
            <td>折扣券标题</td>
            <td>
                <input type="text" v-model="info.Discount_Title">
            </td>
        </tr>
        <tr>
            <td>折扣券颜色</td>
            <td>
                <input type="text" v-model="info.Discount_Color">
            </td>
        </tr>
        <tr>
            <td>剩余库存量</td>
            <td>
                <input type="number" v-model="info.Discount_Num">
            </td>
        </tr>
        <tr>
            <td>每人限领</td>
            <td>
                <input type="number" v-model="info.Discount_Limited">
            </td>
        </tr>
        <tr>
            <td>使用条件</td>
            <td>
                <input type="text" v-model="info.Discount_Use">
            </td>
        </tr>
        <tr>
            <td>折扣</td>
            <td>
                <input type="number" v-model="info.Discount_Discount">
            </td>
        </tr>
        <tr>
            <td>开始日期</td>
            <td>
                <input type="date" v-model="info.Discount_StartTime">
            </td>
        </tr>
        <tr>
            <td>截止日期</td>
            <td>
                <input type="date" v-model="info.Discount_EndTime">
            </td>
        </tr>
        <tr>
            <td>适用业务</td>
            <td>
                <input type="text" v-model="info.Discount_Business">
            </td>
        </tr>
        <tr>
            <td>使用须知</td>
            <td>
                <textarea v-model="info.Discount_Precautions"></textarea>
            </td>
        </tr>
        <tr>
            <td>客服电话</td>
            <td>
                <input type="text" v-model="info.Discount_Phone">
            </td>
        </tr>
        <tr>
            <td>优惠券图片</td>
            <td>
                <img style="width: 60px;height: 80px;" :src="info.Imgs">
                <input type="file" @change="FileUpLoads">
            </td>
        </tr>
        <tr>
            <td>门店</td>
            <td>
                <select v-model="info.ShopId">
                    <option :value="0">--请选择--</option>
                    <option :value="1">明镜台</option>
                    <option :value="2">上弦月</option>
                    <option :value="3">永夜星河</option>
                    <!-- <option  v-for="item in Shop" :value="item.Shop_Id">{{ item.Shop_Name }}</option> -->
                </select>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="保存" @click="SaveData">
            </td>
        </tr>
    </table>

</template>
<script setup lang="ts">
import axios from 'axios';
import { onMounted,ref } from 'vue';


//文件上传
const FileUpLoads=(e:any)=>{
let obj=e.target.files[0]
let f=new FormData()
f.append("file",obj)


axios.post('https://localhost:7153/api/FileUpLoad/UploadImg',f)

.then((res)=>{
    console.log(res)

    info.value.Imgs=res.data.data

}).catch((err=>{


}
))

}
const info=ref({
    Discount_Title:"",
    Discount_Color:"",
    Discount_Num:"",
    Discount_Limited:"",
    Discount_Use:"",
    Discount_Discount:"",
    Discount_StartTime:"",
    Discount_EndTime:"",
    Discount_Business:"",
    Discount_Precautions:"",
    Discount_Phone:"",
    Imgs:"",
    ShopId:0

})

const Shop=ref([{
    Shop_Id:0,
    Shop_Name:""
}])


//下拉




   // alert(111111)

    // axios.get("https://localhost:7153/api/Discount/ShowShop")
    // .then(res=>{
    //     console.log(res.data)
    //     Shop.value=res.data
    
    // })

   // axios.get("https://localhost:7153/api/Discount/ShowShop")
    //.then(res=>{
      //  console.log(res.data)
      //  Shop.value=res.data;
    //})


//}


const SaveData=()=>{

    axios.post('https://localhost:7153/api/Discount/AddDiscounts',info.value)
    .then(res=>{
        if(res.data==-1){
            alert("标题已经存在");
        }
        else if(res.data>0){
            alert("添加成功");
        }
        else{
            alert("添加失败");
        }
    })


}





</script>